<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * BackendPro
 *
 * A website backend system for developers for PHP 4.3.2 or newer
 *
 * @package         conlabz CMS
 * @author          Christian Schneider
 * @copyright       Copyright (c) 2009
 * @license         
 * @link            http://www.conlabz.de
 * @filesource
 */

// ---------------------------------------------------------------------------


/**
 * Weather_model
 *
 * Model used to retrive weather for a website
 *
 * @package			conlabz CMS
 * @subpackage		Models
 */
class Weather_model extends Model {
	function Weather_model( ) {
		parent::Model( );
		
		log_message( 'debug', 'conlabz CMS : Weather_model class loaded' );
	}

	
	function getXML( $domain )
    {
		$town = $this->getTownByDomain( $domain );	
        $xmlfile = "http://www.google.com/ig/api?weather=" . $town;
        $xmlRaw = file_get_contents( $xmlfile );

        $xmlData = $this->simplexml->xml_parse( $xmlRaw );
		
        echo "<pre>";
        echo $xmlData['weather']['forecast_information']['city']['@attributes']['data'] . "<br />";
        print_r( $xmlData );
		/* foreach( $xmlData['item'] as $row )
        {

		$result .= '<tr>';
		$result .= '<td>'.$row['id'].'</td>';
		$result .= '<td>'.$row['name'].'</td>';
		$result .= '<td>'.$row['category'].'</td>';
		$result .= '<td>$ '.$row['price'].'</td>';
		$result .= '</tr>';

        } */
        
        //return $result;
	}
	
	/**
	 * Get Town by Domain
	 *
	 * @access public
	 * @param string $domain Domain of the using website
	 * @return string
	 */
	function getTownByDomain( $domain ) {
		$this->db->select( 'weather.town_name'
						   );
		$this->db->from( "weather" );
		$this->db->from( "category" );
		$this->db->from( "domain" );
		
		$whereString = "`weather`.`category_id`=`category`.`id` 
				AND `weather`.`category_language_id`=`category`.`language_id` 
				AND `category`.`website_id`=`domain`.`website_id` 
				AND `domain`.`url`='" . $domain."'";
		$this->db->where( $whereString );
		
		$query = $this->db->get( ); 
		$row = $query->result_array( );
		if( !empty( $row ) ) {
			return $row[0]['town_name'];
		}
	}
	
	
}
/* End of file weather_model.php */
/* Location: ./modules/weather/models/weather_model.php */